/*************************************************
Author: tony
Date: 12/10/2012
Description:
Notes:
*************************************************/

#ifndef __CClanEntry_h__
#define __CClanEntry_h__

#include "commclass.h"
#include "CTArray.h"
#include "../shop/CShopConfig.h"
#include "../storage/CUserStorage.h"
#include "../battle/CBattleData.h"

enum EN_CLAN_LOG_TYPE
{
    CLAN_LOG_MEMBER = 2, //成员动态日志 (取值跟协议MsgReqUserClanInfo.info_type字段对应)
    CLAN_LOG_EVENT  = 7, //家族事件日志
};

enum EN_CLAN_LOG
{
    CLAN_LOG_CREATE = 1,        //XX创建了家族
    CLAN_LOG_VICE   = 2,        //XX被提升为副族长
    CLAN_LOG_JOIN   = 3,        //XX加入了家族
    CLAN_LOG_LITE   = 4,        //XX通过不懈努力成功晋升为家族精英
    CLAN_LOG_QUIT   = 5,        //XX退出了家族
    CLAN_LOG_FORCE  = 6,        //XX被踢出了家族
    CLAN_LOG_REPUT  = 7,        //XX获得XX声望，为家族贡献了XX建设度
    CLAN_LOG_NORM   = 8,        //XX被解除副族长职位
    CLAN_LOG_DONATE = 9,        //XX通过捐献,获得了XX贡献度,同时为家族增加了XX建设度
    CLAN_LOG_CONT    = 11,      //XX获得了XX贡献度，同时为家族贡献了XX点建设度
    MAX_CLAN_MEMBER_LOG_ID = 100,

    CLAN_LOG_UPGRAD  = 101,       //家族事件: 在所有成员的努力下家族成功升级到XX级
    CLAN_LOG_RECOMMEND  = 102,    //族长XX长时间未登陆,系统推荐XX为族长
    CLAN_LOG_BONUS  = 103,        //族长XX刚刚进行了家族战利品分配，请各位成员尽快领取
    CLAN_LOG_TREE_UPGRADE  = 104, //通过大家的努力浇灌，XX神树升级到XX级
};

class CShopItemConfig;
class CClanEntryShop
{
public:
    CClanEntryShop ()
    {
        Clear();
    }

    void Clear ()
    {
        _iLastRefreshTime = 0;
        _astItems.Clear();
    }

    //刷新家族商店物品
    int ReNewShopItem (unsigned char ucClanLevel);
    int GetShopItem (unsigned char ucPos, CShopItemConfig & stShopItem);
    bool HasSameItem (CDropItemData & stItem);

    int _iLastRefreshTime;   //上次刷新物品的时间
    CTArray<CShopItemConfig, MAX_CLAN_SHOP_ITEM>  _astItems;
};

typedef CTArray<unsigned int , CLAN_VICE_LEADER_NUM + 1>  T_CLAN_MANAGER;
class CClanEntry
{
public:
    CClanEntry ()
    {
        Clear();
    }

    void Clear ()
    {
        _uiClanId = 0;
        _ucAcademyType = 0;
        _ucClanLevel = 0;
        _iConstruction = 0;
        _usClanRank = 0;
        _usClanFightingRank = 0;
        _astClanMember.Clear();
        _astJoinReq.Clear();
        _astClanLog.Clear();
        _iDissMissTime = 0;
        _stClanShop.Clear();
        _uiChangerGid = 0;
        _iLastRecommdTime = 0;
        _iAuctionBuffTime = 0;
        _stTree.Clear();
        _stDiceRank.Clear();
        _usDailyRecruitCnt.SetDefault(0);
    }

    static int CountSize ()
    {
        return CUserStorage::CountSize();
    }

    int Init(const char* sBuff)
    {
        return _stStorage.Init(sBuff);
    }

    int GetClanMember (unsigned int uiGid, CClanMember & stMember);

    int GetClanLeader (unsigned int & uiGid);

    void GetManager (T_CLAN_MANAGER & stManager);

    int GetClanVice (unsigned int & uiVice1, unsigned int & uiVice2);

    //申请加入请求
    int AddJoinReq (unsigned int uiGid);

    int DelJoinReq (unsigned int uiGid);

    //增加家族成员
    int AddNewMember (const CClanMember & stMember);

    //移出家族成员
    int RemoveMember (unsigned int uiGid);

    //获取指定职位的人数
    int GetMemberCount (unsigned char ucTitle);

    //获取指定等级的家族最大人数
    int GetMaxMemberCount ();

    int SetMemberTitle (unsigned int uiGid, unsigned char ucTitle);

    //增加今日贡献度
    int AddTodayContri (unsigned int uiGid, int iContribution);

    //增加日志
    int AddLog (CClanLog & stLog);

    //刷新家族精英 (家族总贡献度排名前5的玩家)
    void RefreshElite ();

    //获取贡献度最高的族长\成员(普通成员+精英成员)
    void GetMostContriGid (unsigned char ucTitle, unsigned int & uiGid);

    //设置压轴竞拍额外奖励的时间
    void SetAuctionBuffTime (int iEndTime);

    //获取压轴竞拍额外奖励的结束时间
    int GetAuctionBuffEndTime ();

    //是否达到最多的成员数
    bool IsMemberFull ();

    //家族中是否有这个成员
    bool HasThisMember (unsigned int uiGid);

    void UpdateDiceRank (unsigned int uiGid, int iBestWeekPos);

    int GetTodayRecuitCnt (int iNowTime);

    void AddTodayRecuitCnt (int iNowTime);

    bool HasLeader ();
public:
    CTSizeString<CLAN_NAME_STRING_SIZE> _szName;   //家族名称
    unsigned int  _uiClanId;      //家族ID
    unsigned char _ucAcademyType; //学院类型
    unsigned char _ucClanLevel;   //家族等级
    int   _iConstruction;         //家族总建设度
    unsigned short _usClanRank;   //家族排名.  (不需要入库,定时算出来的)
    unsigned short _usClanFightingRank;   //家族战排名
    CTArray<CClanMember, MAX_CLAN_MEMBER_COUNT>  _astClanMember;   //家族成员
    CTArray<unsigned int, MAX_CLAN_JOIN_REQ_NUM + 1> _astJoinReq;  //加入家族申请
    CTArray<CClanLog, MAX_CLAN_LOG_NUM> _astClanLog;          //家族日志
    unsigned int _uiChangerGid; //修改公告者的GID
    CTSizeString<MAX_CLAN_NOTICE_STRING_LEN>  _szNotice;  //家族公告
    int _iDissMissTime;   //家族解散时间
    int _iLastRecommdTime;  //上次家族自荐的时间
    int _iAuctionBuffTime;  //设置压轴竞拍额外奖励的时间
    CClanEntryShop _stClanShop;  //家族商店
    CUserStorage _stStorage;

    CTreeData _stTree;

    CMagicDoorData _stMagicDoor;//魔界传送门数据

    CDiceRank _stDiceRank;

    CDailyReflushUShort _usDailyRecruitCnt;
};

#endif // __CClanEntry_h__
